<template>
  <ContentWrap>
    <!-- 搜索工作栏 -->
    <el-form
      class="-mb-15px"
      :model="queryParams"
      ref="queryFormRef"
      :inline="true"
      label-width="68px"
    >
      <el-form-item label="日期区间" prop="loginDate">
        <el-date-picker
          v-model="queryParams.dayScope"
          :default-time="[new Date('1 00:00:00'), new Date('1 23:59:59')]"
          class="!w-240px"
          end-placeholder="结束日期"
          start-placeholder="开始日期"
          type="daterange"
          value-format="YYYY-MM-DD"
        />
      </el-form-item>
      <el-form-item>
        <el-button @click="handleQuery"><Icon icon="ep:search" class="mr-5px" /> 搜索</el-button>
      </el-form-item>
    </el-form>
  </ContentWrap>
  <!-- 列表 -->
  <ContentWrap>
    <el-descriptions :column="3" label-class-name="desc-label">
      <el-descriptions-item label="收入">
        {{ divide(summer.income, 100) }}
      </el-descriptions-item>
      <el-descriptions-item label="收入总手续费">{{
        divide(summer.commissOfIncome, 100)
      }}</el-descriptions-item>
      <el-descriptions-item label="收入总到账"
        ><el-tag size="mini" type="success">{{
          divide(summer.allIncome, 100)
        }}</el-tag></el-descriptions-item
      >
      <el-descriptions-item label="退款">{{ divide(summer.refund, 100) }} </el-descriptions-item>
      <el-descriptions-item label="退手续费">{{
        divide(summer.commissOfRefund, 100)
      }}</el-descriptions-item>
      <el-descriptions-item label="总退账"
        ><el-tag size="mini" type="danger">{{
          divide(summer.allRefund, 100)
        }}</el-tag></el-descriptions-item
      >
      <el-descriptions-item label="净收入">
        <el-tag size="mini" type="success">{{ divide(summer.resultIncome, 100) }}</el-tag>
      </el-descriptions-item>
    </el-descriptions>
  </ContentWrap>
  <!-- 分割线 -->
  <el-divider />

  <!-- 列表 -->
  <ContentWrap>
    <el-table v-loading="loading" :data="list" :stripe="true" :show-overflow-tooltip="true">
      <el-table-column label="时间" align="center" prop="calcDay" />
      <el-table-column label="收入" align="center">
        <template #default="scope">
          {{ divide(scope.row.income, 100) }}
        </template>
      </el-table-column>
      <el-table-column label="收入总手续费" align="center">
        <template #default="scope">
          {{ divide(scope.row.commissOfIncome, 100) }}
        </template>
      </el-table-column>
      <el-table-column label="收入总到账" align="center">
        <template #default="scope">
          {{ divide(scope.row.allIncome, 100) }}
        </template>
      </el-table-column>
      <el-table-column label="退款" align="center">
        <template #default="scope">
          {{ divide(scope.row.refund, 100) }}
        </template>
      </el-table-column>
      <el-table-column label="退手续费" align="center">
        <template #default="scope">
          {{ divide(scope.row.commissOfRefund, 100) }}
        </template>
      </el-table-column>
      <el-table-column label="总退账" align="center">
        <template #default="scope">
          {{ divide(scope.row.allRefund, 100) }}
        </template>
      </el-table-column>
      <el-table-column label="净收入" align="center">
        <template #default="scope">
          {{ divide(scope.row.resultIncome, 100) }}
        </template>
      </el-table-column>
    </el-table>
    <Pagination
      :total="total"
      v-model:page="queryParams.pageNo"
      v-model:limit="queryParams.pageSize"
      @pagination="getList"
    />
  </ContentWrap>
</template>
<script lang="ts" setup>
import { divide } from '@/utils/tools'
import {
  getPayElecDayReportSummerOfOwnMember,
  getPayElecDayReportPageOfOwnMember
} from '@/api/zwsj/payElecDayReport'

defineOptions({ name: 'OwnPayElecDayReport' })

const loading = ref(false) // 列表的加载中
const total = ref(0) // 列表的总页数
const list = ref() // 列表的数据
const summer = ref({}) // 总览数据

const queryParams = reactive({
  pageNo: 1,
  pageSize: 10,
  dayScope: [],
  startDay: undefined,
  endDay: undefined,
  ownMemberUserId: undefined
})

const queryFormRef = ref() // 搜索的表单

/** 查询总览 */
const getSummer = async () => {
  try {
    const data = await getPayElecDayReportSummerOfOwnMember(queryParams)
    summer.value = data
  } finally {
  }
}

/** 查询列表 */
const getList = async () => {
  loading.value = true
  try {
    const data = await getPayElecDayReportPageOfOwnMember(queryParams)
    list.value = data.list
    total.value = data.total
  } finally {
    loading.value = false
  }
}

/** 搜索按钮操作 */
const handleQuery = () => {
  queryParams.pageNo = 1

  queryParams.startDay = queryParams.dayScope[0]
  queryParams.endDay = queryParams.dayScope[1]
  getSummer()
  getList()
}

const props = defineProps({
  ownMemberUserId: {
    type: Number,
    required: true
  }
})

watch(
  () => props.ownMemberUserId,
  () => (queryParams.ownMemberUserId = props.ownMemberUserId),
  { immediate: true }
)

/** 初始化 **/
onMounted(() => {
  //   console.info(props.ownMemberUserId)
  //   queryParams.ownMemberUserId = props.ownMemberUserId
})
</script>
